package com.andaily.web.controller.mobile.log;

import com.andaily.domain.dto.log.LogCommentDto;
import com.andaily.domain.dto.log.LogSettingDto;
import com.andaily.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/log/setting")
public class LogSettingController {

    @Autowired
    private LogService logService;

    @RequestMapping(value = "form", method = RequestMethod.GET)
    public String showForm(Model model) throws Exception {
        LogSettingDto logSettingDto = logService.loadLogSettingDto();
        model.addAttribute("logSettingDto", logSettingDto);
        return "log/log_setting_form";
    }

    @RequestMapping(value = "form", method = RequestMethod.POST)
    public String submit(@ModelAttribute("logSettingDto") LogSettingDto logSettingDto) throws Exception {
        logService.updateLogSetting(logSettingDto);
        return "redirect:form?result=true";
    }

}
